package com.mesd.framework.util;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {
	public static Date getCurrentDateStart(){
		Calendar time = Calendar.getInstance();
		time.set(Calendar.HOUR, 0);
		time.set(Calendar.MINUTE, 0);
		time.set(Calendar.SECOND, 0);
		time.set(Calendar.MILLISECOND, 0);
		return time.getTime();
	}
	
	public static Date getCurrentDateTime(){
		return new Date();
	}
	
	public static Date getCurrentDateEnd(){
		Calendar time = Calendar.getInstance();
		time.set(Calendar.HOUR, 23);
		time.set(Calendar.MINUTE, 59);
		time.set(Calendar.SECOND, 59);
		time.set(Calendar.MILLISECOND,999);
		return time.getTime();
	}
	
	public static Timestamp convertDateToTimeStamp(Date time){
		return new Timestamp(time.getTime());
	}
	
	public static Date convertTimeStampToDate(Timestamp timestamp){
		Calendar time =  Calendar.getInstance();
		time.setTimeInMillis(timestamp.getTime());
		return time.getTime();
	}
	
	public static String convertTimeStampToString(Timestamp timestamp){
		try {
			Date date = convertTimeStampToDate(timestamp);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			return sdf.format(date);
		} catch (Exception e) {
			return null;
		}
	}
}
